class PackDetailResponse {
  final int code;
  final PackDetail? data;
  final String msg;

  PackDetailResponse({
    required this.code,
    required this.data,
    required this.msg,
  });

  factory PackDetailResponse.fromJson(Map<String, dynamic> json) {
    return PackDetailResponse(
      code: json['code'] as int,
      data: json['data'] != null ? PackDetail.fromJson(json['data']) : null,
      msg: json['msg'] ??'',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'code': code,
      'data': data?.toJson(),
      'msg': msg,
    };
  }
}

class PackDetail {
  final int id;
  final int warehouse;
  final int order;
  final String shipmentCode;
  final String status;
  final OrderInfo orderInfo;
  final ItemInfo itemInfo;
  final List<ReceivingShipmentLine> receivingShipmentLines;

  PackDetail({
    required this.id,
    required this.warehouse,
    required this.order,
    required this.shipmentCode,
    required this.status,
    required this.orderInfo,
    required this.itemInfo,
    required this.receivingShipmentLines,
  });

  factory PackDetail.fromJson(Map<String, dynamic> json) {
    return PackDetail(
      id: json['id'] as int,
      warehouse: json['warehouse'] as int,
      order: json['order'] as int,
      shipmentCode: json['shipment_code'] ??'',
      status: json['status'] ??'',
      orderInfo: OrderInfo.fromJson(json['order_info']),
      itemInfo: ItemInfo.fromJson(json['item_info']),
      receivingShipmentLines: (json['receiving_shipment_lines'] as List)
          .map((e) => ReceivingShipmentLine.fromJson(e))
          .toList(),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'warehouse': warehouse,
      'order': order,
      'shipment_code': shipmentCode,
      'status': status,
      'order_info': orderInfo.toJson(),
      'item_info': itemInfo.toJson(),
      'receiving_shipment_lines': receivingShipmentLines.map((e) => e.toJson()).toList(),
    };
  }
}

class OrderInfo {
  final int id;
  final String orderNumber;
  final String orderType;

  OrderInfo({
    required this.id,
    required this.orderNumber,
    required this.orderType,
  });

  factory OrderInfo.fromJson(Map<String, dynamic> json) {
    return OrderInfo(
      id: json['id'] as int,
      orderNumber: json['order_number'] ??'',
      orderType: json['order_type'] ??'',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'order_number': orderNumber,
      'order_type': orderType,
    };
  }
}

class ItemInfo {
  final int id;
  final String itemNumber;
  final String internalItemNumber;
  final String name;
  final String shortDescription;

  ItemInfo({
    required this.id,
    required this.itemNumber,
    required this.internalItemNumber,
    required this.name,
    required this.shortDescription,
  });

  factory ItemInfo.fromJson(Map<String, dynamic> json) {
    return ItemInfo(
      id: json['id'] as int,
      itemNumber: json['item_number'] ??'',
      internalItemNumber: json['internal_item_number'] ??'',
      name: json['name'] ??'',
      shortDescription: json['short_description'] ??'',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'item_number': itemNumber,
      'internal_item_number': internalItemNumber,
      'name': name,
      'short_description': shortDescription,
    };
  }
}

class ReceivingShipmentLine {
  final int id;
  final String lineNumber;
  final String? lpnNumber;
  final String itemNumber;
  final String packKey;
  final int orderPackQuantity;
  final int shippedPackQuantity;
  final int receivedQuantity;
  final String packType;
  final int quantity;
  final String status;
  final String itemName;
  final String shortDescription;

  ReceivingShipmentLine({
    required this.id,
    required this.lineNumber,
    required this.lpnNumber,
    required this.itemNumber,
    required this.packKey,
    required this.orderPackQuantity,
    required this.shippedPackQuantity,
    required this.receivedQuantity,
    required this.packType,
    required this.quantity,
    required this.status,
    required this.itemName,
    required this.shortDescription,
  });

  factory ReceivingShipmentLine.fromJson(Map<String, dynamic> json) {
    return ReceivingShipmentLine(
      id: json['id'] as int,
      lineNumber: json['line_number'] ??'',
      lpnNumber: json['lpn_number']??'N/A',
      itemNumber: json['item_number'] ??'',
      packKey: json['pack_key'] ??'',
      orderPackQuantity: json['order_pack_quantity'] as int,
      shippedPackQuantity: json['shipped_pack_quantity'] ??0,
      receivedQuantity: json['received_quantity'] ??0,
      packType: json['pack_type'] ??'',
      quantity: json['quantity'] as int,
      status: json['status'] ??'',
      itemName: json['item_name'] ??'',
      shortDescription: json['short_description'] ??'',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'line_number': lineNumber,
      'item_number': itemNumber,
      'pack_key': packKey,
      'order_pack_quantity': orderPackQuantity,
      'shipped_pack_quantity': shippedPackQuantity,
      'received_quantity': receivedQuantity,
      'pack_type': packType,
      'quantity': quantity,
      'status': status,
      'item_name': itemName,
      'short_description': shortDescription,
    };
  }
}

class OrderLine {
  final int id;
  final int shipmentLineId;
  final String itemNumber;
  final int quantity;
  final String name;
  final String shortDescription;

  OrderLine({
    required this.id,
    required this.shipmentLineId,
    required this.itemNumber,
    required this.quantity,
    required this.name,
    required this.shortDescription,
  });

  factory OrderLine.fromJson(Map<String, dynamic> json) {
    return OrderLine(
      id: json['id'] as int,
      shipmentLineId: json['shipment_line_id'] as int,
      itemNumber: json['item_number'] ??'',
      quantity: json['quantity'] as int,
      name: json['name'] ??'',
      shortDescription: json['short_description'] ??'',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'shipment_line_id': shipmentLineId,
      'item_number': itemNumber,
      'quantity': quantity,
      'name': name,
      'short_description': shortDescription,
    };
  }
}